home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bench / ds3100.md / RCS / printStats.c,v < prev   
Encoding:
Text File  |  1989-08-01  |  24.8 KB  |  755 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.07.31.17.54.19;  author douglis;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     89.07.26.23.20.51;  author douglis;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @port to the ds3100
  27. @
  28. text
  29. @/*
  30.  * printStats.c --
  31.  *    Routines to print out program execution times, and filesystem stats.
  32.  */
  33.  
  34. #include "sprite.h"
  35. #include "status.h"
  36. #include "sys/ioctl.h"
  37. #include "sys/file.h"
  38. #include "stdio.h"
  39. #include "proc.h"
  40. #include "vm.h"
  41. #include "sysStats.h"
  42. #include "kernel/fs.h"
  43. #include "kernel/fsStat.h"
  44. #include "kernel/sched.h"
  45. #include "kernel/vm.h"
  46.  
  47.  
  48.  
  49. /*
  50.  *----------------------------------------------------------------------
  51.  *
  52.  * PrintTimes --
  53.  *
  54.  *    Print the resource usage (user and kernel CPU time) and elapsed time.
  55.  *
  56.  * Results:
  57.  *    None.
  58.  *
  59.  * Side effects:
  60.  *    Prints to the specified stream
  61.  *
  62.  *----------------------------------------------------------------------
  63.  */
  64. void
  65. PrintTimes(stream, usagePtr, timePtr)
  66.     FILE *stream;
  67.     Proc_ResUsage *usagePtr;
  68.     Time *timePtr;
  69. {
  70.     Time delta;
  71.     if (usagePtr != NULL) {
  72.     Time_Add(usagePtr->userCpuUsage, usagePtr->childUserCpuUsage,
  73.                      &delta);
  74.     fprintf(stream, "%d.%03du ", delta.seconds,
  75.                    delta.microseconds / 1000);
  76.     Time_Add(usagePtr->kernelCpuUsage, usagePtr->childKernelCpuUsage,
  77.                      &delta);
  78.     fprintf(stream, "%d.%03ds ", delta.seconds,
  79.                    delta.microseconds / 1000);
  80.     }
  81.     if (timePtr != NULL) {
  82.     int seconds = timePtr->seconds;
  83.     if (seconds >= 3600) {
  84.         fprintf(stream, "%d:", seconds / 3600);
  85.         seconds = seconds % 3600;
  86.     }
  87.     if (seconds >= 60) {
  88.         fprintf(stream, "%d:", seconds / 60);
  89.         seconds = seconds % 60;
  90.     }
  91.     fprintf(stream, "%d.%03d", seconds,
  92.                    timePtr->microseconds / 1000);
  93.     }
  94.     fprintf(stream, "\n");
  95. }
  96.  
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * PrintIdleTime --
  102.  *
  103.  *    Given two samples sched module statistics, this computes
  104.  *    the differenc in idle ticks and, using the time, computes
  105.  *    a utilization.
  106.  *
  107.  * Results:
  108.  *    None.
  109.  *
  110.  * Side effects:
  111.  *    Prints to the specified stream
  112.  *
  113.  *----------------------------------------------------------------------
  114.  */
  115. void
  116. PrintIdleTime(stream, startSchedPtr, endSchedPtr, timePtr)
  117.     FILE *stream;
  118.     Sched_Instrument *startSchedPtr, *endSchedPtr;
  119.     Time *timePtr;
  120. {
  121.     register     highTicks;
  122.     double     lowTicks;
  123.     int        cpu;
  124.  
  125.     Sched_Instrument zeroStats;
  126.     if (startSchedPtr == NULL) {
  127.     bzero(&zeroStats, sizeof(Sched_Instrument));
  128.     startSchedPtr = &zeroStats;
  129.     }
  130.  
  131.     for (cpu=0; cpu<MACH_MAX_NUM_PROCESSORS; cpu++) {
  132.         highTicks = endSchedPtr->processor[cpu].idleTicksOverflow -
  133.         startSchedPtr->processor[cpu].idleTicksOverflow;
  134.         lowTicks = endSchedPtr->processor[cpu].idleTicksLow 
  135.         - startSchedPtr->processor[cpu].idleTicksLow;
  136.  
  137.         if (highTicks != 0) {
  138.         fprintf(stream, "(High ticks = %d)", highTicks);
  139.         }
  140.         if (timePtr->seconds == 0 && timePtr->microseconds == 0) {
  141.         fprintf(stream, "Idle ticks --/-- = 100%% Idle, Elapsed time ");
  142.         } else {
  143.         lowTicks /= 
  144.           (double)timePtr->seconds 
  145.             + (double) (timePtr->microseconds)/1000000.;
  146.         fprintf(stream, "Idle ticks %0.0f/%d = %6.2f%% Idle, Context Sw. %d inv %d full %d, Elapsed time ",
  147.                    lowTicks,
  148.             endSchedPtr->processor[cpu].idleTicksPerSecond,
  149.             (double)lowTicks/(double)endSchedPtr->processor[cpu].idleTicksPerSecond * 100.,
  150.             endSchedPtr->processor[cpu].numContextSwitches 
  151.                 - startSchedPtr->processor[cpu].numContextSwitches,
  152.                    endSchedPtr->processor[cpu].numInvoluntarySwitches 
  153.                 - startSchedPtr->processor[cpu].numInvoluntarySwitches,
  154.                    endSchedPtr->processor[cpu].numFullCS 
  155.                 - startSchedPtr->processor[cpu].numFullCS);
  156.         }
  157.         PrintTimes(stream, (Proc_ResUsage *)0, timePtr);
  158.     }
  159. }
  160.  
  161.  
  162. /*
  163.  *----------------------------------------------------------------------
  164.  *
  165.  * PrintFsStats --
  166.  *
  167.  *    Print out the filesystem statistics.  If both a start and end
  168.  *    sample of the statistics are given then the differences between
  169.  *    the two are printed.  To just print the total cumulative statistics
  170.  *    from one sample, specify a single FsStats buffer with the 'end'
  171.  *    parameter.
  172.  *
  173.  * Results:
  174.  *    None.
  175.  *
  176.  * Side effects:
  177.  *    Prints to the specified stream
  178.  *
  179.  *----------------------------------------------------------------------
  180.  */
  181. void
  182. PrintFsStats(stream, start, end, verbose)
  183.     FILE *stream;    /* Output stream */
  184.     FsStats *start;    /* 0, or address of "before run" statistics */
  185.     FsStats *end;    /* End of run statistics */
  186.     int verbose;    /* If true, everything is dumped */
  187. {
  188.     register int t1, t2, t3, t4, t5;
  189.     FsStats zeroStats;
  190.  
  191.     if (start == (FsStats *)0) {
  192.     bzero(&zeroStats, sizeof(FsStats));
  193.     start = &zeroStats;
  194.     }
  195.     /*
  196.      * Print cache size
  197.      */
  198.     fprintf(stream, "Cache blocks max %d min %d number %d/%d free %d/%d limit %d\n",
  199.                end->blockCache.maxCacheBlocks,
  200.                end->blockCache.minCacheBlocks,
  201.                start->blockCache.numCacheBlocks,
  202.                end->blockCache.numCacheBlocks,
  203.                start->blockCache.numFreeBlocks,
  204.                end->blockCache.numFreeBlocks,
  205.                end->blockCache.maxNumBlocks);
  206.  
  207.     /*
  208.      * Print bytes read traffic ratio
  209.      */
  210.     t1 = end->blockCache.bytesRead - start->blockCache.bytesRead;
  211.     t2 = end->blockCache.dirBytesRead - start->blockCache.dirBytesRead;
  212.     t3 = end->gen.remoteBytesRead - start->gen.remoteBytesRead;
  213.     t4 = end->gen.fileBytesRead - start->gen.fileBytesRead;
  214.     t5 = end->gen.physBytesRead - start->gen.physBytesRead;
  215.     fprintf(stream, "Bytes read %d+%d remote %d disk %d+%d",
  216.                t1, t2, t3, t4, t5);
  217.     if (t1 + t2 > 0) {
  218. #ifdef stupid_compiler
  219.     fprintf(stream, "\ttraffic ratio %%%d\n",
  220.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  221. #else
  222.     fprintf(stream, "\n");
  223. #endif
  224.     } else {
  225.     fprintf(stream, "\n");
  226.     }
  227.  
  228.     /*
  229.      * Print bytes written traffic ratio
  230.      */
  231.     t1 = end->blockCache.bytesWritten - start->blockCache.bytesWritten +
  232.     (end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  233.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites) *
  234.     FS_BLOCK_SIZE;
  235.     t2 = end->blockCache.dirBytesWritten - start->blockCache.dirBytesWritten;
  236.     t3 = end->gen.remoteBytesWritten - start->gen.remoteBytesWritten;
  237.     t4 = end->gen.fileBytesWritten - start->gen.fileBytesWritten;
  238.     t5 = end->gen.physBytesWritten - start->gen.physBytesWritten;
  239.     fprintf(stream, "Bytes written %d+%d remote %d disk %d+%d",
  240.                t1, t2, t3, t4, t5);
  241. #ifdef stupid_compiler
  242.     if (t1 + t2 > 0) {
  243.     fprintf(stream, "\ttraffic ratio %%%d",
  244.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  245.     }
  246. #endif
  247.     fprintf(stream, "\n");
  248.  
  249.     if (verbose) {
  250.     /*
  251.      * Print device bytes and zero fills
  252.      */
  253.     t1 = end->gen.deviceBytesWritten - start->gen.deviceBytesWritten;
  254.     t2 = end->gen.deviceBytesRead - start->gen.deviceBytesRead;
  255.     fprintf(stream, "Dev bytes read %d written %d\n", t1, t2);
  256.     t1 = end->blockCache.readZeroFills - start->blockCache.readZeroFills;
  257.     t2 = end->blockCache.writeZeroFills1 -
  258.         start->blockCache.writeZeroFills1;
  259.     t3 = end->blockCache.writeZeroFills2 -
  260.         start->blockCache.writeZeroFills2;
  261.     t4 = end->blockCache.fragZeroFills - start->blockCache.fragZeroFills;
  262.     fprintf(stream, "Zero Fills read %d write1 %d write2 %d frag %d\n",
  263.                    t1, t2, t3, t4);
  264.     t1 = end->blockCache.appendWrites - start->blockCache.appendWrites;
  265.     t2 = end->blockCache.overWrites - start->blockCache.overWrites;
  266.     t3 = end->blockCache.domainReadFails -
  267.         start->blockCache.domainReadFails;
  268.     fprintf(stream, "Appends %d Overwrites %d Failed Reads %d\n",
  269.                    t1, t2, t3);
  270.     }
  271.     t1 = end->blockCache.readAccesses - start->blockCache.readAccesses +
  272.      end->blockCache.fragAccesses - start->blockCache.fragAccesses +
  273.      end->blockCache.fileDescReads - start->blockCache.fileDescReads +
  274.      end->blockCache.indBlockAccesses - start->blockCache.indBlockAccesses +
  275.      end->blockCache.dirBlockAccesses - start->blockCache.dirBlockAccesses;
  276.     t2 = end->blockCache.readHitsOnDirtyBlock -
  277.     start->blockCache.readHitsOnDirtyBlock;
  278.     t3 = end->blockCache.readHitsOnCleanBlock -
  279.     start->blockCache.readHitsOnCleanBlock;
  280.     t4 = end->blockCache.fragHits - start->blockCache.fragHits +
  281.      end->blockCache.fileDescReadHits - start->blockCache.fileDescReadHits +
  282.      end->blockCache.indBlockHits - start->blockCache.indBlockHits +
  283.      end->blockCache.dirBlockHits - start->blockCache.dirBlockHits;
  284.     fprintf(stream, "Cache reads %d hits: dirty %d clean %d other %d",
  285.                t1, t2, t3, t4);
  286. #ifdef stupid_compiler
  287.     if (t1 != 0) {
  288.     fprintf(stream, "\thit ratio %%%d",
  289.                (int)((double)(t2+t3+t4)/(double)t1 * 100.));
  290.     }
  291. #endif
  292.     fprintf(stream, "\n");
  293.  
  294.     t1 = end->blockCache.readAheads - start->blockCache.readAheads;
  295.     t2 = end->blockCache.readAheadHits - start->blockCache.readAheadHits;
  296.     t3 = end->blockCache.allInCacheCalls - start->blockCache.allInCacheCalls;
  297.     t4 = end->blockCache.allInCacheTrue - start->blockCache.allInCacheTrue;
  298.     if (t1 > 0) {
  299.     fprintf(stream, "Read Ahead: hits %d/%d all-in-cache %d/%d\n",
  300.             t2, t1, t4, t3);
  301.     }
  302.  
  303.     t1 = end->blockCache.writeAccesses - start->blockCache.writeAccesses +
  304.      end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  305.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites +
  306.      end->blockCache.dirBlockWrites - start->blockCache.dirBlockWrites;
  307.     t2 = end->blockCache.partialWriteHits - start->blockCache.partialWriteHits +
  308.     end->blockCache.fileDescWriteHits - start->blockCache.fileDescWriteHits;
  309.     t3 = end->blockCache.partialWriteMisses -
  310.     start->blockCache.partialWriteMisses;
  311.     t4 = end->blockCache.blocksWrittenThru -
  312.     start->blockCache.blocksWrittenThru;
  313.     fprintf(stream, "Cache writes %d hits %d misses %d thru %d",
  314.                t1, t2, t3, t4);
  315. #ifdef stupid_compiler
  316.     if (t1 != 0) {
  317.     fprintf(stream, "\ttraffic ratio %%%d",
  318.                (int)((double)(t3+t4)/(double)t1 * 100.));
  319.     }
  320. #endif
  321.     fprintf(stream, "\n");
  322.     
  323.     fprintf(stream, "Write thru %d data %d indirect %d desc %d dir %d\n",
  324.                t4,
  325.                end->blockCache.dataBlocksWrittenThru -
  326.                start->blockCache.dataBlocksWrittenThru,
  327.                end->blockCache.indBlocksWrittenThru -
  328.                start->blockCache.indBlocksWrittenThru,
  329.                end->blockCache.descBlocksWrittenThru -
  330.                start->blockCache.descBlocksWrittenThru,
  331.                end->blockCache.dirBlocksWrittenThru -
  332.                start->blockCache.dirBlocksWrittenThru);
  333.     if (end->blockCache.fileDescReads > 0) {
  334.     fprintf(stream, "File descriptor reads %d hits %d writes %d hits %d\n",
  335.                    end->blockCache.fileDescReads -
  336.                    start->blockCache.fileDescReads,
  337.                    end->blockCache.fileDescReadHits -
  338.                    start->blockCache.fileDescReadHits,
  339.                    end->blockCache.fileDescWrites -
  340.                    start->blockCache.fileDescWrites,
  341.                    end->blockCache.fileDescWriteHits -
  342.                    start->blockCache.fileDescWriteHits);
  343.     }
  344.     if (end->blockCache.indBlockAccesses > 0) {
  345.     fprintf(stream, "Indirect block reads %d hits %d writes %d\n",
  346.                end->blockCache.indBlockAccesses -
  347.                start->blockCache.indBlockAccesses,
  348.                end->blockCache.indBlockHits -
  349.                start->blockCache.indBlockHits,
  350.                end->blockCache.indBlockWrites -
  351.                start->blockCache.indBlockWrites);
  352.     }
  353.     if (end->blockCache.dirBlockAccesses > 0) {
  354.     fprintf(stream, "Directory block reads %d hits %d writes %d\n",
  355.                    end->blockCache.dirBlockAccesses -
  356.                    start->blockCache.dirBlockAccesses,
  357.                    end->blockCache.dirBlockHits -
  358.                    start->blockCache.dirBlockHits,
  359.                    end->blockCache.dirBlockWrites -
  360.                    start->blockCache.dirBlockWrites);
  361.     }
  362.     if (end->blockCache.vmRequests > 0) {
  363.     fprintf(stream, "VM requests %d tried %d gave %d\n",
  364.                    end->blockCache.vmRequests -
  365.                    start->blockCache.vmRequests,
  366.                    end->blockCache.triedToGiveToVM -
  367.                    start->blockCache.triedToGiveToVM,
  368.                    end->blockCache.vmGotPage -
  369.                    start->blockCache.vmGotPage);
  370.     }
  371.     fprintf(stream, "Cache blocks created %d, alloc from free %d part %d lru %d\n",
  372.                    end->blockCache.unmapped -
  373.                    start->blockCache.unmapped,
  374.                    end->blockCache.totFree -
  375.                    start->blockCache.totFree,
  376.                    end->blockCache.partFree -
  377.                    start->blockCache.partFree,
  378.                    end->blockCache.lru -
  379.                    start->blockCache.lru);
  380.     if (end->alloc.blocksAllocated > 0) {
  381.     fprintf(stream, "Disk blocks alloc %d free %d search %d/%d hash %d\n",
  382.                    end->alloc.blocksAllocated -
  383.                    start->alloc.blocksAllocated,
  384.                    end->alloc.blocksFreed -
  385.                    start->alloc.blocksFreed,
  386.                    end->alloc.cylsSearched -
  387.                    start->alloc.cylsSearched,
  388.                    end->alloc.cylBitmapSearches -
  389.                    start->alloc.cylBitmapSearches,
  390.                    end->alloc.cylHashes -
  391.                    start->alloc.cylHashes);
  392.     fprintf(stream, "Fragments alloc %d free %d upgrade %d blocks made %d used %d, bad hints %d\n",
  393.                    end->alloc.fragsAllocated -
  394.                    start->alloc.fragsAllocated,
  395.                    end->alloc.fragsFreed -
  396.                    start->alloc.fragsFreed,
  397.                    end->alloc.fragUpgrades -
  398.                    start->alloc.fragUpgrades,
  399.                    end->alloc.fragToBlock -
  400.                    start->alloc.fragToBlock,
  401.                    end->alloc.fullBlockFrags -
  402.                    start->alloc.fullBlockFrags,
  403.                    end->alloc.badFragList -
  404.                    start->alloc.badFragList);
  405.     }
  406.     if (end->nameCache.accesses > 0) {
  407.     fprintf(stream, "Name cache entries %d accesses %d hits %d replaced %d\n",
  408.                end->nameCache.size,
  409.                end->nameCache.accesses -
  410.                start->nameCache.accesses,
  411.                end->nameCache.hits -
  412.                start->nameCache.hits,
  413.                end->nameCache.replacements -
  414.                start->nameCache.replacements);
  415.     }
  416.     fprintf(stream, "Handles %d created %d installed %d hits %d old %d version %d flush %d\n",
  417.                end->handle.exists,
  418.                end->handle.created -
  419.                start->handle.created,
  420.                end->handle.installCalls -
  421.                start->handle.installCalls,
  422.                end->handle.installHits -
  423.                start->handle.installHits,
  424.                0,
  425.                end->handle.versionMismatch -
  426.                start->handle.versionMismatch,
  427.                end->handle.cacheFlushes -
  428.                start->handle.cacheFlushes);
  429.     fprintf(stream, "\tfetched %d hits %d released %d locks %d/%d wait %d\n",
  430.                end->handle.fetchCalls -
  431.                start->handle.fetchCalls,
  432.                end->handle.fetchHits -
  433.                start->handle.fetchHits,
  434.                end->handle.release -
  435.                start->handle.release,
  436.                end->handle.locks -
  437.                start->handle.locks,
  438.                end->handle.locks -
  439.                start->handle.locks,
  440.                end->handle.lockWaits -
  441.                start->handle.lockWaits);
  442.     fprintf(stream, "Segments fetched %d hits %d\n",
  443.                end->handle.segmentFetches -
  444.                start->handle.segmentFetches,
  445.                end->handle.segmentHits -
  446.                start->handle.segmentHits);
  447.     fprintf(stream, "Lookup relative %d absolute %d redirect %d found %d loops %d timeouts %d stale %d\n",
  448.                end->prefix.relative -
  449.                start->prefix.relative,
  450.                end->prefix.absolute -
  451.                start->prefix.absolute,
  452.                end->prefix.redirects -
  453.                start->prefix.redirects,
  454.                end->prefix.found -
  455.                start->prefix.found,
  456.                end->prefix.loops -
  457.                start->prefix.loops,
  458.                end->prefix.timeouts -
  459.                start->prefix.timeouts,
  460.                end->prefix.stale -
  461.                start->prefix.stale);
  462. }
  463.  
  464.  
  465. /*
  466.  *----------------------------------------------------------------------
  467.  *
  468.  * PrintDiskStats --
  469.  *
  470.  *    Print out statistics for the disks.  If both a start and end
  471.  *    sample of the statistics are given then the differences between
  472.  *    the two are printed.  To just print the total cumulative statistics
  473.  *    from one sample, specify a single VmStats buffer with the 'end'
  474.  *    parameter.
  475.  *
  476.  * Results:
  477.  *    None.
  478.  *
  479.  * Side effects:
  480.  *    Prints to the specified stream
  481.  *
  482.  *----------------------------------------------------------------------
  483.  */
  484. void
  485. PrintDiskStats(stream, start, end)
  486.     FILE        *stream;    /* Output stream */
  487.     Sys_DiskStats    *start;    /* 0, or address of "before run" statistics */
  488.     Sys_DiskStats    *end;    /* End of run statistics */
  489. {
  490.     int    i = 0;
  491.     while (1) {
  492.     if (end[i].name[0] == 0) {
  493.         return;
  494.     }
  495.     if (start == 0) {
  496.         fprintf(stream, "Disk (%s, %d): %0.2f%% Idle Reads %d Writes %d\n",
  497.             end[i].name, end[i].controllerID,
  498.             100 * ((float)end[i].idleCount / (float)end[i].numSamples),
  499.             end[i].diskReads, end[i].diskWrites);
  500.     } else {
  501.         fprintf(stream, "Disk (%s, %d) %0.0f%% Idle Reads %d Writes %d\n",
  502.             end[i].name, end[i].controllerID,
  503.             100 * ((float)(end[i].idleCount - start[i].idleCount) /
  504.                    (float)(end[i].numSamples - start[i].numSamples)),
  505.             end[i].diskReads - start[i].diskReads,
  506.             end[i].diskWrites - start[i].diskWrites);
  507.     }
  508.     i++;
  509.     }
  510. }
  511.  
  512.  
  513. /*
  514.  *----------------------------------------------------------------------
  515.  *
  516.  * PrintVmStats --
  517.  *
  518.  *    Print out VM statistics.  If both a start and end
  519.  *    sample of the statistics are given then the differences between
  520.  *    the two are printed.  To just print the total cumulative statistics
  521.  *    from one sample, specify a single VmStats buffer with the 'end'
  522.  *    parameter.
  523.  *
  524.  * Results:
  525.  *    None.
  526.  *
  527.  * Side effects:
  528.  *    Prints to the specified stream
  529.  *
  530.  *----------------------------------------------------------------------
  531.  */
  532. void
  533. PrintVmStats(stream, start, end)
  534.     FILE *stream;    /* Output stream */
  535.     Vm_Stat *start;    /* 0, or address of "before run" statistics */
  536.     Vm_Stat *end;    /* End of run statistics */
  537. {
  538.     register    int    *diffPtr;
  539.     register    int    *startPtr;
  540.     register    int    *endPtr;
  541.     int            i;
  542.     int            inusePages;
  543.     int            totPages;
  544.     int            numModifiedPages;
  545.     Vm_Stat        diffStat;
  546.     int            totPercent;
  547.     int            totFaults;
  548.     int            heapPercent;
  549.     int            stkPercent;
  550.     int            quickPercent;    
  551.     int            totHits;
  552.     int            totPrefetches;
  553.     int            hitPct;
  554.  
  555.     startPtr = (int *)start;
  556.     endPtr = (int *)end;
  557.     diffPtr = (int *)&diffStat;
  558.  
  559.     for (i = 0; 
  560.          i < sizeof(Vm_Stat) / sizeof(int); 
  561.      i++, startPtr++, endPtr++, diffPtr++) {
  562.     *diffPtr = *endPtr - *startPtr;
  563.     }
  564.  
  565.     (void)Vm_Cmd(VM_COUNT_DIRTY_PAGES, &numModifiedPages);
  566.     fprintf(stream, "Kernel VM Pages: %d (Code+Data=%d Stacks=%d)\n",
  567.          end->kernMemPages + end->kernStackPages,
  568.          end->kernMemPages, end->kernStackPages);
  569.     inusePages = end->numDirtyPages + end->numUserPages;
  570.     totPages = end->numFreePages + inusePages;
  571.     fprintf(stream, "User VM Pages:   %d (Free=%d Dirty=%d Res=%d Alloc-list=%d)\n",
  572.         end->numFreePages + end->numDirtyPages + 
  573.         end->numReservePages + end->numUserPages, 
  574.         end->numFreePages, end->numDirtyPages,
  575.         end->numReservePages,
  576.         end->numUserPages);
  577.     fprintf(stream, "Modified pages: Total=%d %%Tot-dirty=%0.2f %%Inuse-dirty=%0.2f\n",
  578.         numModifiedPages,
  579.         (float) (numModifiedPages) / (float)totPages * 100.0,
  580.         (float) (numModifiedPages) / (float)inusePages * 100.0);
  581.     fprintf(stream, "FS Pages: Current=%d Max=%d Min=%d\n", 
  582.         end->fsMap - end->fsUnmap, end->maxFSPages, end->minFSPages);
  583.     fprintf(stream,
  584.          "Faults: %8d (Zero=%d FS=%d Swap=%d Quick=%d Coll=%d)\n", 
  585.          diffStat.totalFaults, diffStat.zeroFilled, diffStat.fsFilled,
  586.          diffStat.psFilled,diffStat.quickFaults, diffStat.collFaults);
  587.     fprintf(stream, "        %8d (Code=%d Heap=%d Stack=%d)\n", 
  588.          diffStat.totalFaults, diffStat.codeFaults, diffStat.heapFaults,
  589.          diffStat.stackFaults);
  590.     fprintf(stream, 
  591.         "Mod page stats:  Pot-mod=%d Not-mod=%d Not-hard-mod=%d\n",
  592.         diffStat.potModPages, diffStat.notModPages, 
  593.         diffStat.notHardModPages);
  594.  
  595.     /*
  596.      * Copy on write. 
  597.      */
  598.     totPages = diffStat.numCOWStkPages + diffStat.numCOWHeapPages;
  599.     totFaults = diffStat.numCOWStkFaults + diffStat.numCOWHeapFaults;
  600.     if (diffStat.numCOWHeapPages > 0) {
  601.     heapPercent = 100.0 * ((float)diffStat.numCOWHeapFaults / 
  602.                       diffStat.numCOWHeapPages);
  603.     } else {
  604.     heapPercent = 0;
  605.     }
  606.     if (diffStat.numCOWStkPages > 0) {
  607.     stkPercent = 100.0 * ((float)diffStat.numCOWStkFaults / 
  608.                       diffStat.numCOWStkPages);
  609.     } else {
  610.     stkPercent = 0;
  611.     }
  612.     if (totPages > 0) {
  613.     totPercent = 100.0 * ((float)totFaults / totPages);
  614.     } else {
  615.     totPercent = 0;
  616.     }
  617.     if (totFaults > 0) {
  618.     quickPercent = 100.0 * ((float)diffStat.quickCOWFaults / totFaults);
  619.     } else {
  620.     quickPercent = 0;
  621.     }
  622.     fprintf(stream, 
  623.         "COW: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  624.         diffStat.numCOWHeapFaults, diffStat.numCOWHeapPages, heapPercent,
  625.         diffStat.numCOWStkFaults, diffStat.numCOWStkPages, stkPercent,
  626.         totFaults, totPages, totPercent);
  627.     fprintf(stream, "     Quick (%d/%d)=%d%%\n",
  628.         diffStat.quickCOWFaults, totFaults, quickPercent);
  629.     /*
  630.      * Copy on reference.
  631.      */
  632.     totPages = diffStat.numCORStkPages + diffStat.numCORHeapPages;
  633.     totFaults = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  634.     if (diffStat.numCORHeapPages > 0) {
  635.     heapPercent = 100.0 * ((float)diffStat.numCORHeapFaults / 
  636.                       diffStat.numCORHeapPages);
  637.     } else {
  638.     heapPercent = 0;
  639.     }
  640.     if (diffStat.numCORStkPages > 0) {
  641.     stkPercent = 100.0 * ((float)diffStat.numCORStkFaults / 
  642.                       diffStat.numCORStkPages);
  643.     } else {
  644.     stkPercent = 0;
  645.     }
  646.     if (totPages > 0) {
  647.     totPercent = 100.0 * ((float)totFaults / totPages);
  648.     } else {
  649.     totPercent = 0;
  650.     }
  651.     fprintf(stream,
  652.             "COR: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  653.         diffStat.numCORHeapFaults, diffStat.numCORHeapPages, heapPercent,
  654.         diffStat.numCORStkFaults, diffStat.numCORStkPages, stkPercent,
  655.         totFaults, totPages, totPercent);
  656.     totPages = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  657.     totFaults = diffStat.numCORCOWStkFaults + diffStat.numCORCOWHeapFaults;
  658.     if (diffStat.numCORCOWHeapFaults > 0) {
  659.     heapPercent = 100.0 * ((float)diffStat.numCORCOWHeapFaults / 
  660.                       diffStat.numCORHeapFaults);
  661.     } else {
  662.     heapPercent = 0;
  663.     }
  664.     if (diffStat.numCORCOWStkFaults > 0) {
  665.     stkPercent = 100.0 * ((float)diffStat.numCORCOWStkFaults / 
  666.                       diffStat.numCORStkFaults);
  667.     } else {
  668.     stkPercent = 0;
  669.     }
  670.     if (totPages > 0) {
  671.     totPercent = 100.0 * ((float)totFaults / totPages);
  672.     } else {
  673.     totPercent = 0;
  674.     }
  675.     fprintf(stream,
  676.             "COR-mod: Heap(%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  677.         diffStat.numCORCOWHeapFaults, diffStat.numCORHeapFaults,heapPercent,
  678.         diffStat.numCORCOWStkFaults, diffStat.numCORStkFaults, stkPercent,
  679.         diffStat.numCORCOWHeapFaults + diffStat.numCORCOWStkFaults,
  680.         diffStat.numCORHeapFaults + diffStat.numCORStkFaults, totPercent);
  681.  
  682.     fprintf(stream, "Swap pages copied: %d\n", diffStat.swapPagesCopied);
  683.     fprintf(stream,
  684.              "Vm allocs: %d (Free=%d From-FS=%d From-alloc-list=%d)\n",
  685.          diffStat.numAllocs, diffStat.gotFreePage, diffStat.gotPageFromFS, 
  686.          diffStat.pageAllocs);
  687.     fprintf(stream, 
  688.          "VM-FS stats: Asked=%d Free-pages=%d Allocs=%d Frees=%d\n",
  689.          diffStat.fsAsked, diffStat.haveFreePage, diffStat.fsMap, 
  690.          diffStat.fsUnmap);
  691.     fprintf(stream, "Alloc-list searches: %d (Free=%d In-use=%d)\n",
  692.          diffStat.numListSearches, diffStat.usedFreePage, 
  693.          diffStat.numListSearches - diffStat.usedFreePage);
  694.     fprintf(stream, "Extra-searches: %d (Lock=%d Ref=%d Dirty=%d)\n",
  695.          diffStat.lockSearched + diffStat.refSearched + 
  696.          diffStat.dirtySearched,
  697.          diffStat.lockSearched, diffStat.refSearched, 
  698.          diffStat.dirtySearched);
  699.     fprintf(stream, "Pages written %d\n", diffStat.pagesWritten);
  700.  
  701.     totPrefetches = diffStat.codePrefetches + diffStat.heapFSPrefetches +
  702.             diffStat.heapSwapPrefetches + diffStat.stackPrefetches;
  703.     if (totPrefetches > 0) {
  704.     totHits = diffStat.codePrefetchHits + diffStat.heapFSPrefetchHits +
  705.           diffStat.heapSwapPrefetchHits + diffStat.stackPrefetchHits;
  706.     fprintf(stream, "Prefetch stats:\n");
  707.     if (diffStat.codePrefetches > 0) {
  708.         hitPct = 100 * ((float)diffStat.codePrefetchHits / 
  709.                 (float)diffStat.codePrefetches);
  710.         fprintf(stream, "    code (%d/%d)=%d%%\n",
  711.             diffStat.codePrefetchHits, diffStat.codePrefetches, hitPct);
  712.     }
  713.     if (diffStat.heapFSPrefetches > 0) {
  714.         hitPct = 100 * ((float)diffStat.heapFSPrefetchHits / 
  715.                 (float)diffStat.heapFSPrefetches);
  716.         fprintf(stream, "    heap-fs (%d/%d)=%d%%\n",
  717.         diffStat.heapFSPrefetchHits, diffStat.heapFSPrefetches, hitPct);
  718.     }
  719.     if (diffStat.heapSwapPrefetches > 0) {
  720.         hitPct = 100 * ((float)diffStat.heapSwapPrefetchHits / 
  721.                 (float)diffStat.heapSwapPrefetches);
  722.         fprintf(stream, "    heap-swp (%d/%d)=%d%%\n",
  723.         diffStat.heapSwapPrefetchHits, diffStat.heapSwapPrefetches, 
  724.         hitPct);
  725.     }
  726.     if (diffStat.stackPrefetches > 0) {
  727.         hitPct = 100 * ((float)diffStat.stackPrefetchHits / 
  728.                 (float)diffStat.stackPrefetches);
  729.         fprintf(stream, "    stack (%d/%d)=%d%%\n",
  730.         diffStat.stackPrefetchHits, diffStat.stackPrefetches, hitPct);
  731.     }
  732.     hitPct = 100 * ((float)totHits / (float)totPrefetches);
  733.     fprintf(stream, "    total (%d/%d)=%d%%\n",
  734.         totHits, totPrefetches, hitPct);
  735.     fprintf(stream, "    aborts=   %d\n", diffStat.prefetchAborts);
  736.     }
  737. }
  738.  
  739. @
  740.  
  741.  
  742. 1.1
  743. log
  744. @Initial revision
  745. @
  746. text
  747. @d709 1
  748. a709 1
  749.  
  750. a710 3
  751.     fprintf(stream, "Contexts stolen %d pmegs stolen %d\n",
  752.          diffStat.machDepStat.stealContext, diffStat.machDepStat.stealPmeg);
  753. }
  754. @
  755.